Skip to content

Support cleanup actions in class completers #23515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2025

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jul 13, 2025

Needed to break the loop between completion of class and companion object. If we try to complete the class first, and completion needs the companion object (for instance for processing an import) then the companion object completion would consult the companion class info for constructor that need a constructor proxy in the object. This can lead to a cyclic reference.

We now break the cycle by delaying adding constructor proxies in this case to be the last completion action of the companion class.

Needed to break the loop between completion of class and companion object.
If we try to complete the class first, and completion needs the companion
object (for instance for processing an import) then the companion object
completion would consult the companion class info for constructor that
need a constructor proxy in the object. This can lead to a cyclic reference.

We now break the cycle by delaying adding constructor proxies in this case
to be the last completion action of the companion class.
Copy link
Member

@mbovel mbovel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if we actually do need the constructor proxy symbol while we complete the class?

I tried:

object ProtocolTransport

class MyAnnotation(arg: () => ProtocolTransport) extends scala.annotation.StaticAnnotation

import ProtocolTransport.*

@MyAnnotation(apply)
class ProtocolTransport()

and was surprised to see it actually sees the symbol and then complains that the constructor proxy cannot be used as a value:

-- [E195] Type Error: defs.scala:7:14 ------------------------------------------
7 |@MyAnnotation(apply)
  |              ^^^^^
  |              constructor proxy method apply cannot be used as a value
  |
  | longer explanation available when compiling with `-explain`

So in that case that seems to be okay.

And in any case, we probably only enable more code to compile with this PR 👍

@odersky odersky merged commit 561a663 into scala:main Jul 14, 2025
29 checks passed
@odersky odersky deleted the fix-22436 branch July 14, 2025 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Annotation on class leads to cyclic reference when importing with wildcard from companion
2 participants